import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-07
 * Time: 20:02
 */
public class Test {
        public static void merge(int[] nums1, int m, int[] nums2, int n) {
            int index1 = m - 1;
            int index2 = n - 1;
            int tailIndex = nums1.length - 1;
            while(index1 >= 0 && index2 >= 0) {
                if(nums1[index1] > nums2[index2]) {
                    nums1[tailIndex--] = nums1[index1--];
                }else {
                    nums1[tailIndex--] = nums2[index2--];
                }
            }
            if(index1 < 0) {
                while(tailIndex >= 0 && index2 >= 0) {
                    nums1[tailIndex--] = nums2[index2--];
                }
            }
        }

    public static void main(String[] args) {
        int[] arr1 = {1,2,3,4,0,0,0};
        int[] arr2 = {3,9,11};
        merge(arr1,arr1.length - 3,arr2,arr2.length);
        System.out.println(Arrays.toString(arr1));
    }
}
